package com.lagou.ipersistence.mapping;

import com.lagou.ipersistence.session.Configuration;
import sun.security.krb5.Config;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author Yan Jiahong
 * Created on 2020/11/20
 */
public class ResultMap {
    private Configuration configuration;
    private String id;
    //返回的类型
    private Class<?> type;
    private List<ResultMapping> resultMappings;
    private List<ResultMapping> constructorResultMappings;
    private List<ResultMapping> propertyResultMappings;
    private Set<String> mappedColumns;
    private Set<String> unMappedColumns;
    
    public static class Builder {
        private final ResultMap resultMap = new ResultMap();
        
        public Builder(Configuration configuration, String id, Class<?> type, List<ResultMapping> resultMappings) {
            resultMap.configuration = configuration;
            resultMap.id = id;
            resultMap.type = type;
        }
        
        public ResultMap build() {
            if (resultMap.id == null) {
                throw new IllegalArgumentException("ResultMap必须要一个ID");
            }
            resultMap.propertyResultMappings = new ArrayList<>();
            resultMap.constructorResultMappings = new ArrayList<>();
            resultMap.setMappedColumns(new HashSet<>());
            resultMap.setUnMappedColumns(new HashSet<>());
            return resultMap;
        }
    }
    
    public Class<?> getType() {
        return type;
    }
    
    public List<ResultMapping> getPropertyResultMappings() {
        return propertyResultMappings;
    }
    
    public List<ResultMapping> getConstructorResultMappings() {
        return constructorResultMappings;
    }
    
    public Set<String> getMappedColumns() {
        return mappedColumns;
    }
    
    public void setMappedColumns(Set<String> mappedColumns) {
        this.mappedColumns = mappedColumns;
    }
    
    public Set<String> getUnMappedColumns() {
        return unMappedColumns;
    }
    
    public void setUnMappedColumns(Set<String> unMappedColumns) {
        this.unMappedColumns = unMappedColumns;
    }
}
